﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using BaseData;
using BaseData.Common;

namespace TaxData.Tax
{
    /// <summary>
    /// 税收预警数据层
    /// </summary>
    public class AlarmData
    {
        /// <summary>
        /// 计算应税
        /// </summary>
        /// <param name="year">年份</param>
        /// <param name="message">返回信息</param>
        /// <returns>是否成功</returns>
        public static bool ComputeTax(int year, ref string message)
        {
            bool isSucc = false;
            SqlParameter p = new SqlParameter("@year", SqlDbType.Int, 8);
            p.Value = year;
            DataTable dt = DataConfig.QueryRecordsByStoredProcedure(BusinessType.DBWrite, "ComputeTax", p);
            if(dt != null && dt.Rows.Count > 0)
            {
                message = dt.Rows[0][0].ToString();
                if (message == "")
                {
                    isSucc = true;
                }
            }
            return isSucc;
        }

        /// <summary>
        /// 获取预警列表
        /// </summary>
        public static DataTable GetList(string strWhere, int pageSize, int page, ref int allCount)
        {
            DataTable dt = new DataTable();
            string condition = " where 1=1" + strWhere;
            string sqlCount = "select count(1) from v_TaxAlarmQuery with(nolock) " + condition;
            allCount = (int)DataConfig.GetSingle(BusinessType.DBRead, sqlCount);
            if (allCount > 0)
            {
                int startNum = (page - 1) * pageSize + 1;
                int endNum = page * pageSize;
                string sqlInner = "select *,ROW_NUMBER() over(order by DepartmentName desc,Name) as RowNumber from v_TaxAlarmQuery a with(nolock) " + condition;
                string sqlUserList = string.Format("SELECT * FROM ({0}) T WHERE T.RowNumber BETWEEN {1} AND {2} order by RowNumber asc", sqlInner, startNum, endNum);
                dt = DataConfig.QueryRecords(BusinessType.DBRead, sqlUserList);
            }
            return dt;
        }
    }
}
